<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>欢迎页面-L-admin1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="../../css/font.css">
		<link rel="stylesheet" href="../../css/xadmin.css">
		<script src="../../js/jquery.min.js"></script>
		<script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../../js/xadmin.js"></script>
		<script src="../../js/jquery-3.1.1.js"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	</head>

	<body>

		<div class="x-body">
			<xblock>
				<button class="layui-btn" onclick="x_admin_show('添加公告','add/operator-add.html',600,300)"><i class="layui-icon"></i>添加</button>
			</xblock>
			<table class="layui-table">
				<thead>
					<tr>
						<th>ID</th>
						<th>发布者</th>
						<th>发布时间</th>
						<th>标题</th>
						<th>内容</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="tbodygg">
					<!-- <tr>
            <td>1</td>
            <td>admin</td>
            <td>2020-08-29T09:18:26.000+00:00</td>
            <td>回家的诱惑</td>
            <td>南山一棵树~~~~~~~~~~~~~~~~</td>
            <td class="td-status">
			    <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
			      <i class="layui-icon">&#xe640;</i>
			    </a>
			</td>
          </tr> -->
				</tbody>
			</table>
			<div class="page">
				<div id="page">

				</div>
			</div>

		</div>
		<script>
			layui.use('laydate', function() {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: '#start' //指定元素
				});

				//执行一个laydate实例
				laydate.render({
					elem: '#end' //指定元素
				});
			});


			/*用户-删除*/
			function member_del(obj, id) {
				layer.confirm('确认要删除吗？', function(index) {
					//发异步删除数据
					$.ajax({
						url: "http://www.longm.top:8080/lm/delNews?newsid=" + id,
						type: "post",
						dataType: 'json',
						headers: {
							'Content-Type': 'application/json',
							'token':window.localStorage.getItem("token")
						},
						data: {},
						async: false,
						success: function(result) {
							console.log(JSON.stringify(result));
							if (result.code === 200) {
								$(obj).parents("tr").remove();
							} else {
								
							}
						}
					});
					layer.msg('删除中.....', {
						icon: 3,
						time: 2000
					});
					
				});
			}
		</script>
		<script type="application/javascript">
			getList(1);
			function getList(pageNum) {
				$.ajax({
					url: "http://www.longm.top:8080/lm/News?pageNum=" + pageNum,
					type: "post",
					dataType: 'json',
					headers: {
						'Content-Type': 'application/json'
					},
					data: {},
					async: true,
					success: function(result) {
						console.log(JSON.stringify(result));
						if (result.code === 200) {
							var tbady = document.querySelector("#tbodygg");
							var data = result.data;
							var page=document.querySelector("#page");
							for (i = 0; i < data.list.length; i++) {
								var tr = document.createElement("tr");
								var id = document.createElement("td");
								var author = document.createElement("td");
								var time = document.createElement("td");
								var title = document.createElement("td");
								var content = document.createElement("td");
								id.innerText = data.list[i].newsid;
								title.innerText = data.list[i].title;
								author.innerText = data.list[i].author;
								var date = new Date(data.list[i].releasetime);
								time.innerText = dateFormat("YYYY-mm-dd HH:MM", date);
								content.innerText = data.list[i].content;
								var status =
									'<td class="td-status"><a title="删除" onclick="member_del(this,' + data.list[i].newsid + ')' +
									'" href="javascript:;">' + '<i class="layui-icon">&#xe640;</i></a></td>';
								tr.appendChild(id);
								tr.appendChild(author);
								tr.appendChild(time);
								tr.appendChild(title);
								tr.appendChild(content);
								tr.innerHTML=tr.innerHTML+status;
								tbady.appendChild(tr);
							};
							page.innerHTML=page.innerHTML+'<a class="prev" href="">&lt;&lt;</a>';
							for(a=0;a<data.pages;a++)
							{
								
								var pagelist='<a class="num" href="">'+(a+1)+'</a>';
								if(a+1==pageNum)
								{
									pagelist='<span class="current">'+(a+1)+'</span>'
								}
								page.innerHTML=page.innerHTML+pagelist;
							}
							page.innerHTML=page.innerHTML+'<a class="next" href="">&gt;&gt;</a>';
						} else {

						}
					}
				});
			};
			function dateFormat(fmt, date) {
			    let ret;
			    const opt = {
			        "Y+": date.getFullYear().toString(),        // 年
			        "m+": (date.getMonth() + 1).toString(),     // 月
			        "d+": date.getDate().toString(),            // 日
			        "H+": date.getHours().toString(),           // 时
			        "M+": date.getMinutes().toString(),         // 分
			        "S+": date.getSeconds().toString()          // 秒
			        // 有其他格式化字符需求可以继续添加，必须转化成字符串
			    };
			    for (let k in opt) {
			        ret = new RegExp("(" + k + ")").exec(fmt);
			        if (ret) {
			            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
			        };
			    };
			    return fmt;
			}	
		</script>
	</body>

</html>
